<include file="Public:header" />
<script src="__PUBLIC__/js/PCASClass.js" type="text/javascript"></script>
<div class="container">
	<!-- Docs nav ================================================== -->
	<div class="page-header" style="border:none; font-size:14px; ">
		<ul class="nav nav-tabs">
		  <li <if condition="$_GET['content'] == 'customer' || $_GET['content'] == ''">class="active"</if>><a  href="{:U('customer/index')}"><img src="__PUBLIC__/img/customer_icon.png"/>&nbsp; {:L('CUSTOMER')}</a></li>
		  <li <if condition="$_GET['content'] == 'resource' "> class="active" </if>><a  href="{:U('customer/index','content=resource')}"><img src="__PUBLIC__/img/customer_source_icon.png"/>&nbsp; {:L('CUSTOMER_POOL')}</a></li>
		  <li><a href="{:U('contacts/index')}"><img src="__PUBLIC__/img/contacts_icon.png"/> &nbsp;{:L('LINKMAN')}</a></li>
		  <li><a href="{:U('customer/cares')}"><img src="__PUBLIC__/img/cares_icon.png"/> &nbsp;{:L('CUMTOMER_CARE')}</a></li>
		  <li><a href="{:U('customer/analytics')}"><img src="__PUBLIC__/img/tongji.png"/> &nbsp;{:L('CLIENT_STATISTICS')}</a></li>
		  <li><a href="http://5kcrm.com/index.php?m=doc&a=index&id=27" target="_blank" style="font-size: 12px;color: rgb(255, 102, 0);"><img width="20px;" src="__PUBLIC__/img/help.png"/> {:L('HELP')}</a></li>
		</ul>
	</div>
	<include file="Public:alert" />
	<if condition="$_GET['content'] != 'resource'">
	<p class="view">
		<b>{:L('UNIFIED_CUSTOMER_VIEW')}</b>
		<img src=" __PUBLIC__/img/by_owner.png"/> <a href="{:U('customer/index')}" <if condition="$Think.get.by eq null">class="active"</if>>{:L('ALL')}</a> |
		<a href="{:U('customer/index','by=me')}" <if condition="$Think.get.by eq 'me'">class="active"</if>>{:L('MY_CLIENTS')}</a> | 
		<a href="{:U('customer/index','by=sub')}" <if condition="$Think.get.by eq 'sub'">class="active"</if>>{:L('SUBORDINATES_TO_THE_CUSTOMER')}</a> &nbsp;  &nbsp; 
		<img src="__PUBLIC__/img/by_time.png"/> 
		<a href="{:U('customer/index','by=today')}" <if condition="$Think.get.by eq 'today'">class="active"</if>>{:L('TODAY_IS_NEW')}</a> | 
		<a href="{:U('customer/index','by=week')}" <if condition="$Think.get.by eq 'week'">class="active"</if>>{:L('THIS_WEEK_THE_NEW')}</a> | 
		<a href="{:U('customer/index','by=month')}" <if condition="$Think.get.by eq 'month'">class="active"</if>>{:L('THIS_MONTH_THE_NEW')}</a>   &nbsp;  
		<a href="{:U('customer/index','by=deleted')}" <if condition="$Think.get.by eq 'deleted'">class="active"</if>><img src="__PUBLIC__/img/task_garbage.png"/> {:L('RECYCLE_BIN')}</a>
		&nbsp; <img src=" __PUBLIC__/img/seach.png"/><a href="{:U('customer/search')}">{:L('ADVANCED_SEARCH')}</a>
	</p>
	</if>
	<div class="row">	
		<div class="span12">
			<ul class="nav pull-left">
				<if condition="$Think.session.admin eq 1 or $Think.get.by neq 'deleted'">
					<div class="btn-group pull-left">
						<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
							&nbsp;{:L('BATCH_OPERATION')}
							<span class="caret"></span>
						</a>
						<ul class="dropdown-menu">
							<li><a id="delete"  style="margin-right: 5px;" href="javascript:void(0)">{:L('BATCH_REMOVE')}</a></li>
							
							<if condition="$Think.get.content eq 'resource'">
							<li><a id="batch_receive"  style="margin-right: 5px;" href="javascript:void(0)">{:L('BATCH_TO_RECEIVE')}</a></li>
							<li><a id="batch_assign"  style="margin-right: 5px;" href="javascript:void(0)">{:L('MASS_DISTRIBUTION')}</a></li>
							<elseif condition="$Think.get.by neq 'deleted'" />
							<li><a id="remove"  style="margin-right: 5px;" href="javascript:void(0)">{:L('BATCH_INTO_THE_CUSTOMER_POOL')}</a></li>
							</if>
						</ul>
					</div>
				</if>
				<li class="pull-left">
					<form class="form-inline" id="searchForm" action="index.php" method="get">
						<ul class="nav pull-left">			
						<li class="pull-left" >
							<select style="width:auto" id="field" onchange="changeCondition()" name="field">
								<option class="" value="">--{:L('PLEASE_SELECT_A_FILTER_CONDITION')}--</option>
								<volist name="field_list" id="v">
									<option class="{$v['form_type']}" value="{$v[field]}" rel="customer">{$v[name]}</option>
								</volist>
								<if condition="$Think.get.content neq 'resource'"><option class="role" value="owner_role_id">{:L('PRINCIPAL')}</option></if>
								<option class="date" value="create_time">{:L('CREATION_TIME')}</option>
								<option class="date" value="update_time">{:L('MODIFICATION_TIME')}</option>
							</select>&nbsp;&nbsp;
						</li>
						<li id="conditionContent" class="pull-left">
							<select id="condition" style="width:auto" name="condition" onchange="changeSearch()">
								<option value="contains">{:L('INCLUDE')}</option>
								<option value="not_contain">{:L('EXCLUSIVE')}</option>
								<option value="is">{:L('YES')}</option>
								<option value="isnot">{:L('ISNOT')}</option>						
								<option value="start_with">{:L('BEGINNING_CHARACTER')}</option>
								<option value="end_with">{:L('TERMINATION_CHARACTER')}</option>
								<option value="is_empty">{:L('Mandatory')}</option>
								<option value="is_not_empty">{:L('ISNOTEMPTY')}</option>
							</select>&nbsp;&nbsp;
						</li>
						<li id="searchContent" class="pull-left">
							<input id="search" type="text" class="input-medium search-query" name="search"/>&nbsp;&nbsp;
						</li>
						<li class="pull-left"> 
							<input type="hidden" name="m" value="customer"/>
							<if condition="$Think.get.by neq null"><input type="hidden" name="by" value="{$Think.get.by}"/></if>
							<button type="button" id="dosearch" class="btn"> <img src="__PUBLIC__/img/search.png"/>  {:L('SEARCH')}</button>
							&nbsp;
						</li>
						<li class="pull-left">
							<div class="btn-group">
								<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
									<img src="__PUBLIC__/img/sms.png">&nbsp;{:L('SEND_SMS')}
									<span class="caret"></span>
								</a>
								
								<ul class="dropdown-menu">
									<li><a id="all_send"  href="javascript:void(0)">{:L('ALL_SEND')}</a></li>
									<li><a id="page_send" href="javascript:void(0)">{:L('PAGE_SEND')}</a></li>
									<li><a id="check_send" href="javascript:void(0)">{:L('CHECK_SEND')}</a></li>
								</ul>
							</div>
							<div class="btn-group">
								<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
									<img src="__PUBLIC__/img/email.png">&nbsp;{:L('SEND_EMAIL')}
									<span class="caret"></span>
								</a>	
								<ul class="dropdown-menu">
									<li><a id="all_send_email"  href="javascript:void(0)">{:L('ALL_SEND')}</a></li>
									<li><a id="page_send_email" href="javascript:void(0)">{:L('PAGE_SEND')}</a></li>
									<li><a id="check_send_email" href="javascript:void(0)">{:L('CHECK_SEND')}</a></li>
								</ul>
							</div>
						</li>
						</ul>
						<input type="hidden" name="act" id="act" value="search"/>					
						<input type="hidden" name="content" <if condition="$_GET['content']">value="resource"</if>/>
					</form>
				</li>
			</ul>
			<div class="pull-right">
				<a href="{:U('Customer/add')}" class="btn btn-primary"><i class="icon-plus"></i>&nbsp; {:L('CREATE_NEW_CUSTOMER')}</a>&nbsp;
				<div class="btn-group">
					<button class="btn btn-primary dropdown-toggle" data-toggle="dropdown"> <i class="icon-wrench"></i>&nbsp; {:L('CLIENT_TOOLS')}<span class="caret"></span></button>
					<ul class="dropdown-menu">
						<!-- <li><a href="{:U('customer/analytics')}" id="analytics"  class="link"> <i class="icon-align-left"> </i>客户统计</a></li> -->
						<li><a id="import_excel" class="link" href="javascript:void(0);"><i class="icon-upload"></i> {:L('IMPORT_CUSTOMER')}</a></li>
						<li><a href="javascript:void(0);" id="excelExport"  class="link"> <i class="icon-download"> </i> {:L('EXPORT_CUSTOMERS')}</a></li>
					</ul>
				</div>
			</div>
		</div>
		
		<div class="span12">
			<form id="form1" action="" method="post">
				<input type="hidden" name="owner_role" id="hidden_owner_id" value="0"/>
				<input type="hidden" name="message_alert" id="hidden_message" value="0"/>
				<input type="hidden" name="sms_alert" id="hidden_sms" value="0"/>
				<input type="hidden" name="email_alert" id="hidden_email" value="0"/>
				<input type="hidden" name="operating_type" id="operating_type" value=""/>
				<table class="table table-hover table-striped table_thead_fixed">
					<if condition="$customerlist eq null">
						<tr><td>----{:L('TEMPORARILY_NO_DATA')}----</td></tr>
					<else/>
					<thead>
						<tr id="childNodes_num">
							<th><input type="checkbox" id="check_all"/></th>
                            <volist name="field_array" id="vo">
								<if condition="C('ismobile') eq 1 and $i  elt 1">
									<th>{$vo.name}</th>
								<elseif condition="C('ismobile') neq 1"/>
									<th>{$vo.name}</th>
								</if>
                            </volist>
							<if condition="$Think.get.content neq 'resource'"><th>{:L('PRINCIPAL')}</th></if>
							<if condition="C('ismobile') neq 1"><th>{:L('FOUNDER')}</th></if>
							<if condition="(C('ismobile') neq 1) and ($Think.get.by eq 'deleted')"><th>{:L('DELETE_THE_PEOPLE')}</th><th>{:L('DELETE_THE_TIME')}</th></if>
							<th>
								<if condition="$_GET['asc_order'] == 'customer.create_time'">
									<a href="{:U('customer/index','desc_order=customer.create_time&'.$parameter)}">{:L('CREATION_TIME')}&nbsp;<img src="__PUBLIC__/img/arrow_up.png"></a>
								<elseif condition="$_GET['desc_order'] == 'customer.create_time'"/>
									<a href="{:U('customer/index','asc_order=customer.create_time&'.$parameter)}">{:L('CREATION_TIME')}&nbsp;<img src="__PUBLIC__/img/arrow_down.png"></a>
								<else/>
									<a href="{:U('customer/index','desc_order=customer.create_time&'.$parameter)}">{:L('CREATION_TIME')}</a>
								</if>
							</th>
							<if condition="$_GET['asc_order'] == 'customer.update_time' and ($Think.get.content neq 'resource' && $Think.get.by neq 'deleted')">
								<th><a href="{:U('customer/index','desc_order=customer.update_time&'.$parameter)}">{:L('FROM_THE_DUE_DAY')}&nbsp;<img src="__PUBLIC__/img/arrow_up.png"></a></th>
							<elseif condition="$_GET['desc_order'] == 'customer.update_time' and ($Think.get.content neq 'resource' && $Think.get.by neq 'deleted')"/>
								<th><a href="{:U('customer/index','asc_order=customer.update_time&'.$parameter)}">{:L('FROM_THE_DUE_DAY')}&nbsp;<img src="__PUBLIC__/img/arrow_down.png"></a></th>
							<elseif condition="$Think.get.content neq 'resource' && $Think.get.by neq 'deleted'"/>
								<th><a href="{:U('customer/index','desc_order=customer.update_time&'.$parameter)}">{:L('FROM_THE_DUE_DAY')}</a></th>
							</if>
							<th>{:L('OPERATION')}</th>
						</tr>
					</thead>
					<tfoot>
						<tr>
							<td id="td_colspan">{$page}</td>
						</tr>
					</tfoot>
					<tbody>
						<volist name="customerlist" id="vo">
							<tr>
								<td>
									<input name="customer_id[]" class="check_list" type="checkbox" value="{$vo.customer_id}"/>
								</td>
                                <volist name="field_array" id="v">
									<if condition="C('ismobile') eq 1 and $i  elt 1">
										<td>
											<if condition="$v['field'] eq 'name'"><a href="{:U('customer/view', 'id='.$vo['customer_id'])}"></if>
												<span style="color:#{$v['color']}">
												<if condition="$v['form_type'] eq 'datetime'">
												{$vo[$v['field']]|date='Y-m-d',###}
												<else />
												{$vo[$v['field']]}
												</if>
												</span>
											<if condition="$v['field'] eq 'name'"></a></if>
										</td>
									<elseif condition="C('ismobile') neq 1"/>
										<td>
											<if condition="$v['field'] eq 'name'"><a href="{:U('customer/view', 'id='.$vo['customer_id'])}"></if>
												<span style="color:#{$v['color']}">
												<if condition="$v['form_type'] eq 'datetime'">
												{$vo[$v['field']]|date='Y-m-d',###}
												<else />
												{$vo[$v['field']]}
												</if>
												</span>
											<if condition="$v['field'] eq 'name'"></a></if>
										</td>
									</if>
                               
                                </volist>
								<if condition="$Think.get.content neq 'resource'">
									<td><notempty name="vo.owner.user_name"><a class="role_info" rel="{$vo.owner.role_id}" href="javascript:void(0)">{$vo.owner.user_name}</a></notempty></td>
								</if>	
								<if condition="C('ismobile') neq 1">
									<td>
										<notempty name="vo.creator.user_name"><a class="role_info" rel="{$vo.creator.role_id}" href="javascript:void(0)">{$vo.creator.user_name}</a></notempty>
									</td>
								</if>
								<if condition="(C('ismobile') neq 1) and ($Think.get.by eq 'deleted')">
									<td><notempty name="vo.delete_role.user_name"><a class="role_info" rel="{$vo.delete_role.role_id}" href="javascript:void(0)">{$vo.delete_role.user_name}</a></notempty></td>
									<td>{$vo.delete_time|date='Y-m-d',###}</td>
								<elseif condition="C('ismobile') neq 1" /><td>{$vo.create_time|date='Y-m-d',###}</td>
								</if>
								<if condition="$Think.get.content neq 'resource' && $Think.get.by neq 'deleted'">
									<td>
										<if condition="!$vo['is_locked'] && $vo['days'] elt 7"><font color="red">{$vo.days}{:L('DAY')}</font><elseif condition="!$vo['is_locked']"/><font color="blue">{$vo.days}{:L('DAY')}</font></if>
									</td>
								</if>			
								<td><a href="{:U('customer/view', 'id='.$vo['customer_id'])}">{:L('CHECK')}</a>&nbsp;
									<if condition="$Think.get.by eq 'deleted'"><a href="{:U('customer/revert', 'id=' . $vo['customer_id'])}">{:L('REDUCTION')}</a>&nbsp;
									<else /><a href="{:U('customer/edit', 'id='.$vo['customer_id'])}">{:L('COMPILE')}</a>
									</if>
									<if condition="$Think.get.content eq 'resource'">
										<a rel="{$vo['customer_id']}" class="fenpei" href="javascript:void(0)">{:L('DISTRIBUTION')}</a> &nbsp;<a href="{:U('customer/receive', 'customer_id='.$vo['customer_id'])}">{:L('RECEIVE')}</a>
									</if>
								</td>
							</tr>
						</volist>
					</tbody>
					</if>
				</table>
			</form>
		</div>
	</div>
</div>
<div class="hide" id="dialog-import" title="{:L('IMPORT_DATE')}">loading...</div>
<div class="hide" id="dialog-role-info" title="{:L('EMPLOYEE_INFORMATION')}">loading...</div>
<div class="hide" id="dialog-fenpei" title="{:L('DISTRIBUTION_OF_CUSTOMERS')}">loading...</div>
<div class="hide" id="dialog-assign" title="{:L('DISTRIBUTION_OF_CUSTOMERS')}">loading...</div>
<script type="text/javascript">
<if condition="C('ismobile') eq 1">width=$('.container').width() * 0.9;<else/>width=600;</if>
$("#dialog-role-info").dialog({
    autoOpen: false,
    modal: true,
	width: width,
	maxHeight: 400,
	position: ["center",100]
});
$("#dialog-import").dialog({
	autoOpen: false,
	modal: true,
	width: width,
	maxHeight: 400,
	position: ["center",100]
});
$("#dialog-fenpei").dialog({
	autoOpen: false,
	modal: true,
	width: width,
	maxHeight: 400,
	position: ["center",100],
	buttons: {
		"Ok": function () {
			$('#fenpei_form').submit();
			$(this).dialog("close");
		},
		"Cancel": function () {
			$(this).dialog("close");
		}
	}
});
$("#dialog-assign").dialog({
	autoOpen: false,
	modal: true,
	width: width,
	maxHeight: 400,
	position: ["center",100],
	buttons: {
		"Ok": function () {
			var owner_role_id = $('input[name="owner_role_id"]').val();
			var message_alert = $('input:checkbox[name="message_alert"]:checked').val();
			var sms_alert = $('input:checkbox[name="sms_alert"]:checked').val();
			var email_alert = $('input:checkbox[name="email_alert"]:checked').val();
			
			$("#hidden_owner_id").val(owner_role_id);
			$("#hidden_message").val(message_alert);
			$("#hidden_sms").val(sms_alert);
			$("#hidden_email").val(email_alert);
			
			$("#form1").attr('action', '{:U("customer/receive")}');
			$('#operating_type').val('assign');
			$("#form1").submit();
			$(this).dialog("close");
		},
		"Cancel": function () {
			$(this).dialog("close");
		}
	}
});
function changeContent(){
	a = $("#select1  option:selected").val();
	window.location.href="{:U('customer/index', 'by=')}"+a;
}
$(function(){
<if condition="$Think.get.field neq null">
	$("#field option[value='{$Think.get.field}']").prop("selected", true);changeCondition();
	$("#condition option[value='{$Think.get.condition}']").prop("selected", true);changeSearch();
	$("#search").prop('value', '{$Think.get.search}');
	<if condition="$_GET['state'] and $_GET['city']">
		new PCAS("state","city","{$Think.get.state}","{$Think.get.city}");
	</if>
	<else />
	$("#field option[value='status_id']").prop("selected", true);changeCondition();
</if>
	

	$("#excelExport").click(function(){
		if(confirm("{:L('CONFIRM_EXPORT_CUSTOMER')}")){
			$("#act").val('excel');	
			$("#searchForm").submit();
		}
	})	
	
	
	$("#check_all").click(function(){
		$("input[class='check_list']").prop('checked', $(this).prop("checked"));
	});
	$('#delete').click(function(){
		if(confirm('{:L('Confirm_to_delete')}')){
			<if condition="$Think.session.admin eq 1 and $Think.get.by eq 'deleted'">
				$("#form1").attr('action', '{:U("customer/completedelete","content=".$_GET['content'])}');
				$("#form1").submit();
			<else />
				$("#form1").attr('action', '{:U("customer/delete","content=".$_GET['content'])}');
				$("#form1").submit();
			</if>
		}
	});
	$('#remove').click(function(){
		if(confirm('{:L('CONFIRMED_IN_THE_CUSTOMER_POOL')}')){
			$("#form1").attr('action', '{:U("customer/remove")}');
			$('#operating_type').attr('value', 'remove');
			$("#form1").submit();
		}
	});
	$("#import_excel").click(function(){
		$('#dialog-import').dialog('open');
		$('#dialog-import').load('{:U("customer/excelimport")}');
	});
	$(".role_info").click(function(){
		$role_id = $(this).attr('rel');
		$('#dialog-role-info').dialog('open');
		$('#dialog-role-info').load('{:U("user/dialoginfo","id=")}'+$role_id);
	});
	$("#check_send").click(function(){
		var id_array = new Array();
		$("input[class='check_list']:checked").each(function(){  
			id_array.push($(this).val());
		});
		if(id_array.length == 0){
			alert('{:L('YOU_HAVE_NOT_CHOSEN_ANY_CUSTOMERS')}');
		}else{
			var customer_ids = id_array.join(",");
			window.open("{:U('setting/sendSms', 'model=customer&customer_ids=')}"+customer_ids);
		}
	});
	$("#check_send_email").click(function(){
		var id_array = new Array();
		$("input[class='check_list']:checked").each(function(){  
			id_array.push($(this).val());
		});
		
		if(id_array.length == 0){
			alert('{:L('YOU_HAVE_NOT_CHOSEN_ANY_CUSTOMERS')}');
		}else{
			var customer_ids = id_array.join(",");
			window.open("{:U('setting/sendemail', 'model=customer&customer_ids=')}"+customer_ids);
		}
	});
	
	$("#page_send").click(function(){
		var id_array = new Array();
		$("input[class='check_list']").each(function(){
			id_array.push($(this).val());
		});
		if(id_array.length == 0){
			alert('{:L('YOU_HAVE_NOT_CHOSEN_ANY_CUSTOMERS')}');
		}else{
			var customer_ids = id_array.join(",");
			window.open("{:U('setting/sendSms', 'model=customer&customer_ids=')}"+customer_ids);
		}
	});
	$("#page_send_email").click(function(){
		var id_array = new Array();
		$("input[class='check_list']").each(function(){
			id_array.push($(this).val());
		});
		if(id_array.length == 0){
			alert('{:L('YOU_HAVE_NOT_CHOSEN_ANY_CUSTOMERS')}');
		}else{
			var customer_ids = id_array.join(",");
			window.open("{:U('setting/sendemail', 'model=customer&customer_ids=')}"+customer_ids);
		}
	});
	$("#all_send_email").click(function(){
		window.open("{:U('setting/sendemail', 'model=customer&customer_ids=all')}");
	});
	
	$("#all_send").click(function(){
		$("#act").val('sms');
		$("#searchForm").submit();
	});
	
	$(".fenpei").click(function(){
		$customer_id = $(this).attr('rel');
		$('#dialog-fenpei').dialog('open');
		$('#dialog-fenpei').load('{:U("customer/fenpei","customer_id=")}'+$customer_id);
	});
	$('#batch_assign').click(function(){
		$('#dialog-assign').dialog('open');
		$('#dialog-assign').load('{:U("customer/fenpei")}');
	});
	$('#batch_receive').click(function(){
		if(confirm('{:L('SURE_YOU_WANT_TO_BATCH_TO_RECEIVE')}')){
			$("#form1").attr('action', '{:U("customer/receive")}');
			$('#operating_type').attr('value', 'receive');
			$("#form1").submit();
		}
	});
	$("#dosearch").click(function(){
		result = checkSearchForm();
		if(result){
			$("#act").val('search');
			$("#searchForm").submit();
		}
	});
	
});
<if condition="$customerlist neq null">
	$nodes_num = document.getElementById("childNodes_num").children.length;
	$("#td_colspan").attr('colspan',$nodes_num);	
</if>	
</script>
<include file="Public:footer" />